using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FiltronASP.Models;
using FiltronASP.Models.DAO;
using FiltronASP.Models.DAO.Extensions;
using FiltronASP.Models.DAO.Interfaces;

namespace FiltronASP.Helpers.Routes
{
    /// <summary>
    /// Klasa pomocnicza do generowania linkow na podstawie mapowan zawartych w klasie zarejestrowanych routow.
    /// </summary>
    public static class PageRoutesHelper
    {
        /// <summary>
        /// Klasa pomocnicza do generowania linkow zwiazanych z routem <code>PagesList</code>.
        /// </summary>
        /// <param name="urlHelper">url helper z c#</param>
        /// <param name="page">strona w paginacji</param>
        /// <param name="pageType">atualny typ strony</param>
        /// <param name="language">aktualna wersja jezykowa</param>
        /// <returns></returns>
        public static string GeneratePagesListRoute(this UrlHelper urlHelper, int? page, PageType pageType, Language language)
        {
            if ((!page.HasValue) || (page <= 0))
            {
                page = 1;
            }   //if
            if (pageType == null)
            {
                PageTypeDAO pageTypeDAO = new PageTypeDAO();
                pageType = pageTypeDAO.GetDefaultPageType(language);
            }   //if page type
            if ((language != null) && (pageType != null))
            {
                return urlHelper.RouteUrl("PagesList", new { page = (page), currentLanguageId = (language.language_id), pageTypeId = (pageType.page_type_id) });
            } else if (language != null) {   //if both
                return urlHelper.RouteUrl("PagesListNoPageType", new { page = (page), currentLanguageId = (language.language_id) });
            } else {   //if lang
                return urlHelper.RouteUrl("PagesListNoPageTypeNorLanguage", new { page = (page) });
            }   //if none
        }

        /// <summary>
        /// Klasa pomocnicza do generowania linkow zwiazanych z routem <code>PagesList</code>.
        /// </summary>
        /// <param name="urlHelper">url helper z c#</param>
        /// <param name="pageType">atualny typ strony</param>
        /// <param name="language">aktualna wersja jezykowa</param>
        /// <returns></returns>
        public static string GeneratePagesListRoute(this UrlHelper urlHelper, PageType pageType, Language language)
        {
            int page = 1;
            if (pageType == null)
            {
                PageTypeDAO pageTypeDAO = new PageTypeDAO();
                pageType = pageTypeDAO.GetDefaultPageType(language);
            }   //if page type
            if ((language != null) && (pageType != null))
            {
                return urlHelper.RouteUrl("PagesList", new { page = (page), currentLanguageId = (language.language_id), pageTypeId = (pageType.page_type_id) });
            }
            else if (language != null)
            {   //if both
                return urlHelper.RouteUrl("PagesListNoPageType", new { page = (page), currentLanguageId = (language.language_id) });
            }
            else
            {   //if lang
                return urlHelper.RouteUrl("PagesListNoPageTypeNorLanguage", new { page = (page) });
            }   //if none
        }

    }
}
